﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SnailGame.Utility.DataAccess;
using System.Configuration;
using System.Collections;
using Com.Crc.PoJo.Model.Resource;

namespace Com.Crc.ResManage.DAL.EquipManage
{
    public class BroadBandManagerOperatorLogDAL
    {
        DataBroker broker = new DataBroker();

        /// <summary>
        /// 删除，修改状态位为0
        /// </summary>
        /// <param name="wlanList"></param>
        /// <returns></returns>
        public bool DeleteOperatorLogData(ArrayList OperatorLogList)
        {
            string id = "";
            for (int i = 0; i < OperatorLogList.Count; i++)
            {
                id += OperatorLogList[i] + ",";
            }
            id = id.Substring(0, id.Length - 1);
            string strSql = @"UPDATE TT_RESOURCE_OperatorLog SET S_STATE='0' WHERE N_ID IN (" + id + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        /// <summary>
        /// 修改OperatorLog信息
        /// </summary>
        /// <param name="data">model实体</param>
        /// <returns></returns>
        public bool UpdateOperatorLogData(OperatorLog data)
        {
            string strSql = @" UPDATE TT_RESOURCE_OperatorLog SET" +
                                    "N_OPER_ID=" + data.N_OPER_ID + @",
                                        D_OPER_TIME='" + data.D_OPER_TIME.ToString("yyyy-MM-dd HH:mm:ss") + @"',
                                        S_CONTENT='" + data.S_CONTENT + @"',
                                        S_DATA='" + data.S_DATA + @"',
                                        S_STATE='" + data.S_STATE + @"',
                                        D_CREATE='" + data.D_CREATE.ToString("yyyy-MM-dd HH:mm:ss") + @"',
                                    WHERE N_OPER_ID=" + data.N_ID;
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        /// <summary>
        /// 新增OperatorLog信息
        /// </summary>
        /// <param name="data">OperatorLog</param>
        /// <returns></returns>
        public bool AddOperatorLogData(OperatorLog data)
        {
            string strSql = @" INSERT INTO TT_RESOURCE_OperatorLog(N_OPER_ID,
                                                                    D_OPER_TIME,
                                                                    S_CONTENT,
                                                                    S_DATA,
                                                                    S_STATE,
                                                                    D_CREATE)
                                    VALUES (" + data.N_OPER_ID + "," +
                                                "'" + data.D_OPER_TIME.ToString("yyyy-MM-dd HH:mm:ss") + "'" + "," +
                                                "'" + data.S_CONTENT + "'" + "," +
                                                "'" + data.S_DATA + "'" + "," +
                                                "'" + data.S_STATE + "'" + "," +
                                                "'" + data.D_CREATE.ToString("yyyy-MM-dd HH:mm:ss") + "'" + "," + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }
        /// <summary>
        /// 查询OperatorLog信息
        /// </summary>
        /// <param name="strBranchID">操作员ID</param>
        /// <returns></returns>
        public System.Data.DataTable QueryOperatorLogData(long strOperatorID)
        {
            string strSql = @" SELECT N_ID,
                                    N_OPER_ID,
                                    D_OPER_TIME,
                                    S_CONTENT,
                                    S_DATA,
                                    S_STATE,
                                    D_CREATE 
                                 FROM TT_RESOURCE_OperatorLog
                                WHERE S_STATE='1' ";
            if (strOperatorID.CompareTo(0) > 0)
            {
                strSql += " AND N_OPER_ID = " + strOperatorID;
            }
            return broker.ExecuteQueryForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }
    }
}
